package com.tang.consumer.rpc;

import com.alibaba.fastjson.JSONObject;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @author Tang
 * @classname ProviderRpc
 * @description [  ]
 * @date 2021/12/20 22:00
 */
@FeignClient(name = "web-provider",path = "/provider",fallbackFactory = ProviderRpc.ProviderRpcFallback.class)
public interface ProviderRpc {

    @GetMapping("/index")
    public JSONObject index();

    @Component
    class ProviderRpcFallback implements FallbackFactory<ProviderRpc> {

        @Override
        public ProviderRpc create(Throwable throwable) {
            return new ProviderRpc(){
                @Override
                public JSONObject index() {
                    return new JSONObject();
                }
            };
        }
    }

}


